package com.tx.studentManager.utils;

import java.util.HashMap;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;

/**
 * 
* @描述 构建返回客户端的DWZ Json串
* @since showlove 1.0
* @version 1.0 2015-8-26 下午5:51:34
* @author 此生唯晴
 */
public class DWZJsonUtil {
	/**
	 * 成功操作返回状态码
	 */
	public static final String RESULT_SUCCESS_CODE="200";
	/**
	 * 操作失败返回状态码
	 */
	public static final String RESULT_FAILURE_CODE="300";
	/**
	 * 关闭当前窗口，closeCurrent
	 */
	public static final String OPER_CLOSE_CURRENT="closeCurrent";
	/**
	 * statusCode,message,navTabId,forwardUrl,callbackType,rel
	 */
	
	/**
	 * 
	* 描述方法的功能
	* @return
	 */
	public static String simpleJsonStr(String statusCode,String message,String callbackType,String navTabId){
		
		return createJsonStr(statusCode, message, callbackType, navTabId, null, null);
	}
	
	public static String createJsonStr(String statusCode,String message,String callbackType,String navTabId,String rel,String forwardUrl){
		HashMap<String, String> jsonMap=new HashMap<>();
		if(StringUtils.isNotBlank(statusCode)){
			jsonMap.put("statusCode", statusCode);
		}
		if (StringUtils.isNotBlank(message)) {
			jsonMap.put("message", message);
		}
		if(StringUtils.isNotBlank(callbackType)){
			jsonMap.put("callbackType", callbackType);
		}
		if (StringUtils.isNotBlank(navTabId)) {
			jsonMap.put("navTabId", navTabId);
		}
		if (StringUtils.isNotBlank(rel)) {
			jsonMap.put("rel", rel);
		}
		if (StringUtils.isNotBlank(forwardUrl)) {
			jsonMap.put("forwardUrl", forwardUrl);
		}
		return JSONObject.fromObject(jsonMap).toString();
	}
	public static void main(String[] args) {
		System.out.println(DWZJsonUtil.createJsonStr("stacode", "message", "callback", "vavId", "rel", null));
	}
}
